import java.util.ArrayList;


public class Player {

	public float buildRate;
	public float attackPower;
	public float egoCostRate;
	

	public ArrayList<Card> hand;
	public int speed;
	public int startingEgo;
	public int egoRegen;
	public int currentEgo;
	public Tower tower;
	public Deck deck;
	public ChargeWheel charges;
	
	public ArrayList<Buff> buffList;
	
	public Player(Deck inDeck){
		
		this();
		
		deck=inDeck;
		hand = new ArrayList<Card>();
		hand.add(deck.drawCard());
		hand.add(deck.drawCard());
		hand.add(deck.drawCard());
		hand.add(deck.drawCard());
		hand.add(deck.drawCard());
		
		charges.setCharge(ChargeWheel.chargeType.LOGIC, 2);
		
		//System.out.println("Hand: " + hand.get(0) +", " + hand.get(1) + ", " + hand.get(2));
		}
	
	public Player()
	{
		deck = new Deck();
		buildRate=1;
		speed=0;
		startingEgo=75;
		egoRegen=15;
		attackPower=1;
		egoCostRate = 1;
		charges = new ChargeWheel();
		createTower();
		currentEgo = startingEgo;
		//System.out.println(tower.toString());
		
		hand = new ArrayList<Card>();
		buffList = new ArrayList<Buff>();
	}
	
	public void useEgo(int ammount){
		currentEgo-=ammount;
		if(currentEgo<0) currentEgo=0;
	}
	
	/**
	 * Creates a tower for the start of the game.
	 */
	public void createTower()
	{
		ArrayList<Block> list = new ArrayList<Block>();
		
		/*
		 * one block of each type
		list.add(new Block(Block.blockType.Logic,40,8));
		list.add(new Block(Block.blockType.Ethics,30,14));
		list.add(new Block(Block.blockType.Deception,30,20));
		list.add(new Block(Block.blockType.Passion,20,20));
		*/
		
		//two generic blocks, 25 tall and with 25 health
		list.add(new Block(Block.blockType.Logic,25,25));
		list.add(new Block(Block.blockType.Passion,25,25));
		
		this.tower = new Tower(list);
	}
	
	
	public float getBuildRate() {
		return buildRate;
	}

	public void setBuildRate(float buildRate) {
		this.buildRate = buildRate;
	}

	public float getAttackPower() {
		return attackPower;
	}

	public void setAttackPower(float attackPower) {
		this.attackPower = attackPower;
	}
	
	public float getEgoCostRate(){
		return egoCostRate;
	}

	public int getSpeed() {
		return speed;
	}

	public void setSpeed(int speed) {
		this.speed = speed;
	}

	public int getStartingEgo() {
		return startingEgo;
	}

	public void setStartingEgo(int startingEgo) {
		this.startingEgo = startingEgo;
	}

	public int getEgoRegen() {
		return egoRegen;
	}

	public void setEgoRegen(int egoRegen) {
		this.egoRegen = egoRegen;
	}

	public int getCurrentEgo() {
		return currentEgo;
	}

	public void setCurrentEgo(int currentEgo) {
		this.currentEgo = currentEgo;
	}

	public Deck getDeck() {
		return deck;
	}

	public void setDeck(Deck deck) {
		this.deck = deck;
	}

	public ChargeWheel getCharges() {
		return charges;
	}

	public void setCharges(ChargeWheel charges) {
		this.charges = charges;
	}
	
	public ArrayList<Card> getHand(){
		return hand;
	}

	public void setHand(ArrayList<Card> hand) {
		this.hand = hand;
	}
	
	public Tower getTower(){
		return tower;
	}

	public void setTower(Tower tower) {
		this.tower = tower;
	}
	
	public void drawCard()
	{
		if(this.deck.getDrawCards().size() == 0)
			drawHand();
		else
			hand.add(deck.drawCard());
	}
	
	public Card playCard(int index)
	{
		return hand.remove(index);
	}
	
	public void drawHand(){ //Draws a new hand
		hand.clear();
		for(int i = 0; i < 5; i++){ //HAND_SIZE
			hand.add(deck.drawCard());
		}
		
	}
	
	public void egoRegen(){ //Ego regen per turn
		this.currentEgo += this.egoRegen;
		if(currentEgo > 200) currentEgo = 200;
	}
	
	public void reset()
	{
		deck.reshuffle();
		buildRate=1;
		speed=0;
		startingEgo=75;
		egoRegen=15;
		attackPower=1;
		charges.reset();
		createTower();
		currentEgo = startingEgo;
		buffList.clear();		
		drawHand();
	}
	
	public ArrayList<Buff> getBuffs(){
		return buffList;
	}
	public void addBuff(Buff buff){
		this.buffList.add(buff);
	}
}
